﻿namespace USElections.ViewModel
{
    using System.ComponentModel;
    using USElections.Classes;

    /// <summary>
    /// LiveTileVotesCastViewModel class.
    /// </summary>
    public class LiveTileVotesCastViewModel : INotifyPropertyChanged
    {
        #region Fields
        private static readonly LiveTileVotesCastViewModel instance = new LiveTileVotesCastViewModel();
        #endregion

        #region Constructor
        /// <summary>
        /// Initializes static members of the LiveTileVotesCastViewModel class.
        /// </summary>
        static LiveTileVotesCastViewModel()
        {
        }

        /// <summary>
        /// Prevents a default instance of the LiveTileVotesCastViewModel class from being created.
        /// </summary>
        private LiveTileVotesCastViewModel()
        {
        }
        #endregion

        #region Events
        /// <summary>
        /// PropertyChanged event.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion

        #region Public Properties
        /// <summary>
        /// Gets DataManager instance.
        /// </summary>
        public static LiveTileVotesCastViewModel Instance
        {
            get
            {
                return LiveTileVotesCastViewModel.instance;
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the Background task is enabled.
        /// </summary>
        public bool Enabled
        {
            get
            {
                return ScheduledAgentTools.GetAllowedToStart(Model.Enums.PeriodicTaskName.LiveTileUpdate);
            }

            set
            {
                ScheduledAgentTools.SetAllowedToStart(Model.Enums.PeriodicTaskName.LiveTileUpdate, this.Description, value);
                this.NotifyPropertyChanged("Enabled");
            }
        }

        /// <summary>
        /// Gets the task description.
        /// </summary>
        public string Description
        {
            get { return "Notify user about newly casted votes through LiveTile"; }
        }
        #endregion

        #region Private methods
        private void NotifyPropertyChanged(string name)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }
        #endregion
    }
}
